import SockJS from "sockjs-client";

const token = localStorage.getItem("authToken"); // 假设 Token 存储在 localStorage 中
const socket = new SockJS("http://localhost:8081/socket.io", null, {
    headers: {
        Authorization: `Bearer ${token}` // 将 Token 放在请求头中
    }
});

socket.onopen = () => {
    console.log("WebSocket 连接成功！");
};

socket.onmessage = (event) => {
    const message = JSON.parse(event.data);
    console.log("收到消息：", message);
};

socket.onerror = (error) => {
    console.error("WebSocket 错误：", error);
};

socket.onclose = (event) => {
    console.log("WebSocket 连接关闭：", event);
};